﻿using System;
using System.Reflection;

namespace Database.Core.Exceptions
{
  /// <summary>
  /// Exception indicating a problem during the type conversion process.
  /// </summary>
  [Serializable]
  public class TypeConversionException : Exception
  {
    private string _propertyName;
    private Type _propertyType;

    /// <summary>
    /// Gets or sets the name of the property.
    /// </summary>
    /// <value>The name of the property.</value>
    public string PropertyName
    {
      get { return _propertyName; }
      set { _propertyName = value; }
    }

    /// <summary>
    /// Gets or sets the type of the property.
    /// </summary>
    /// <value>The type of the property.</value>
    public Type PropertyType
    {
      get { return _propertyType; }
      set { _propertyType = value; }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="TypeConversionException"/> class.
    /// </summary>
    public TypeConversionException()
    { }

    /// <summary>
    /// Initializes a new instance of the <see cref="TypeConversionException"/> class.
    /// </summary>
    /// <param name="propertyInfo">The property information.</param>
    /// <param name="message">The message.</param>
    /// <param name="innerException">The inner exception.</param>
    public TypeConversionException(PropertyInfo propertyInfo, string message, Exception innerException)
      : base(message, innerException)
    {
      _propertyName = propertyInfo.Name;
      _propertyType = propertyInfo.PropertyType;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="TypeConversionException"/> class.
    /// </summary>
    /// <param name="type">The type for conversion.</param>
    /// <param name="message">The message.</param>
    /// <param name="innerException">The inner exception.</param>
    public TypeConversionException(Type type, string message, Exception innerException)
      : base(message, innerException)
    {
      _propertyName = null;
      _propertyType = type;
    }

  }
}
